<template>
  <section class="statistics-export">
    <a-button type="primary" @click="handlerExport(item)" :auth="item.auth || null" icon="export" v-for="item in buttons" :key="item.value">{{ item.label }}</a-button>
  </section>
</template>

<script lang="ts">
import { Mixins, Component, Watch, Vue, Prop } from 'vue-property-decorator'
import { State, Mutation, Getter, namespace } from 'vuex-class'
import { execlExportServices } from '@/common/services/export'
import { permission } from '@/store/modules/permission'

import { exportDataHandler } from '@/utils/execl'

// @ts-ignore
import fileds from './field.json';

type IExportMethods = keyof typeof execlExportServices

export interface IButton {
  value: IExportMethods;
  auth?: string;
  label: string
}

@Component({
  components: {
  }
})
export default class AdminList extends Vue {
  @Prop({
    type: String
  })
  public currentId!: string

  public buttons: IButton[] = [
    {
      value: 'exportFieldList',
      auth: 'statistics-export.field',
      label: '导出：农户确权面积与粮食种植面积数据'
    },
    {
      value: 'exportPayList',
      auth: 'statistics-export.pay',
      label: '导出：补贴名单与资金分配计划数据'
    },
    {
      value: 'exportPayCountList',
      auth: 'statistics-export.pay-count',
      label: '导出：提交给银行的资金兑付名单与批次汇总审定单'
    }
  ]

  @Watch('currentId', { immediate: true })
  public handlerCurrentIdChange() {
  }

  public getDocument() {
  }

  public handlerEditDocument() {
  }

  public handlerExport(item: IButton) {
    execlExportServices[item.value]({
      s_a_id: this.currentId
    }).then(_ => {
      if (!_.data.length) {
        this.$message.error("暂无数据导出");
        return
      }
      // @ts-ignore
      exportDataHandler(_.data, fileds[item.value], item.label.slice(3) + '.xlsx')
    })
  }

  public mounted() {
  }
  
}
</script>

<style scoped lang="less">
.statistics-export {
  display: flex;
  flex-direction: column;
  width: fit-content;
  button {
    margin-top: 10px;
    text-align: left;
  }
}
</style>
